define([
        //3.加载依赖的库
        'jquery',
        'knockout',
        'text!./acc.html',
        'bootstrap',
   //     'uui',
        'director',
    //    'grid',
   //     'dragJW',
        'domReady!',
        'datatables.net-bs',
        // 'datatables.net-buttons',
        'datatables.net-autofill-bs',
        'net-jszip',
        'net-pdfmake',
        'datatables.net-buttons-bs',
        'datatables.net-colreorder',
        'datatables.net-rowreorder',
        'datatables.net-select',
        'datatables.net-scroller',
        'datatables.net-fixedHeader',
        // 'datatables.net-editor',
        'datatables.net-keyTable',
        'datatables.net-editor-bs',
        'datatables.net-responsive',
        'jstree',
    ],
    function($, ko, template) {
        var viewModelAcc = {
            data : ko.observable({}),
            accDataTable: new u.DataTable({
                meta: {
                    'id':{},
                    'nd': {},
                    'accBookTypeCode': {},
                    'accNo': {},
                    'pCode': {},
                    'accName': {},
                    'accLevel': {},
                    'balDir': {},
                    'isFDwAssCheck': {},
                    'isEaccAssCheck': {}
                }
            }),
            comBalDir: [{
                "value": "DR",
                "name": "借方"
            },{
                "value": "CR",
                "name": "贷方"
            }]
        }


        // viewModelAcc.getCritAcc = function(){
        //     app.serverEvent().addDataTable("accDataTable", "all").fire({
        //         url: $ctx + '/evt/dispatch',
        //         ctrl: 'baseData.critAcc.critAccController',
        //         method: 'loadCritAcc',
        //         success: function (data) {
        //             //console.log(viewModelAcc.accDataTable);
        //         }
        //     })
        // }

        viewModelAcc.searchAcc = function() {
            var acc_nd = $("#nd").val();
            if(acc_nd == "请选择会计年度"){
                acc_nd = "";
            }
            var queryData = {};
            queryData["search_EQ_nd"] = acc_nd;
            // queryData["search_LIKE_dicName"] = dic_name;
            viewModelAcc.accDataTable.addParams(queryData);
            app.serverEvent().addDataTable("accDataTable", "all").fire({
                url: $ctx + '/evt/dispatch',
                ctrl: 'baseData.critAcc.critAccController',
                method: 'loadCritAcc',
                success: function (data) {}
            })

        }
        var init = function(){
            ko.cleanNode($('.content')[0]);
            app = u.createApp(
                {
                    el:'.content',
                    model: viewModelAcc
                }
            );
            
//            var initTree = function () {
//                $('#jstree_demo').jstree({
//                        "core": {
//                            "animation": 0,// 打开或者关闭树的动画时间
//                            "check_callback": true, //检查回调
//                            'force_text': true, 
//                            "themes": {"stripes": true},
//                            'data': {
//                                "dataType": "json",
//                                'url': "/agcfs/baseData/critAcc/getAccTree",
//                                // 'async': false,
//                                'cache': false,
//                                'data': function (node) {
//                                    return {'id': node.id};
//                                }
//                            }
//                        },
//                        "types": {
//                            "#": {"max_children": 1, "max_depth": 4, "valid_children": ["root"]},
//                            "root": {"valid_children": ["default"]},
//                            "default": {"valid_children": ["default", "file"]},
//                            "file": {"icon": "glyphicon glyphicon-file", "valid_children": []}
//                        },
//                        "plugins": ["contextmenu", "dnd", "search", "state", "types", "wholerow"]
//                    }).on('changed.jstree', function (e, data) {
//                        var nodeData = data.instance.get_node(data.selected[0]).original;
//                        if (typeof(nodeData) != "undefined") {
//                            searchCond = JSON.stringify({
//                                nd:nodeData.nd,
//                                reportType: nodeData.code
//                            });
//                            $('#reportlist').DataTable().ajax.reload(null,true);
//                        }
//                    });
//            }
            var table = $('#acc-grid').DataTable({
                language: {
                	"info": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                	 "paginate": {
                         "first": "首页",
                         "previous": "前一页",
                         "next": "后一页",
                         "last": "尾页"
                     },
                    //"url": "chinese.lang.json"
                    select: {
                        rows: {
                            _: '%d 行被选择',
                            0: '',
                            1: '1行被选择'
                        }
                    }
                },
                colReorder: true,
                //rowReorder: true,
                lengthChange: false,
                searching:false,
                // "bScrollCollapse": false,
                //      pagingType: 'full_numbers',
                paging: true,
                serverSide: true,
//                "dom": '<"wrapper"flipt>',
                ajax: {
                    url: "/agcfs/baseData/critAcc/getAccList",
                    dataType: "json",
                },
                scrollX: true,
                scrollY: true,
                // scrollY:        200,
                //deferRender:    true,
                // scroller:       true,
//                fixedColumns: {        /*1.5.4 有bug,错位*/
//                    leftColumns: 2
//                },
//                 responsive: true,
                rowid: "id",
                columns: [
                    {   // Checkbox select column
                        data: null,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false
                    },
                    {data: "nd"},
                    {data: "accBookTypeCode"}, //科目体系编码
                    {data: "accNo"},  //科目编号
                    {data: "pCode"}, //上级科目编码
                    {data: "accName"}, //科目名称
                    {data: "accLevel"}, //科目级次
                    {data: "balDir"}, // 余额方向
                    {   // Checkbox select column
                        data: isFDwAssCheck,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false
                    },
                    {   // Checkbox select column
                        data: isEaccAssCheck,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false
                    },
//                    {data: "isFDwAssCheck"}, //按往来单位核算
//                    {data: "isEaccAssCheck"}, //按经济分类核算
                ],
                order: [ 1, 'asc' ], //通过第一列排序 然后重绘表格并维持当前分页的信息
                
                select: {
                    style: 'multi', /* os,single,multi, multi+shift,api*/
                    selector: 'td.select-checkbox',
                }
            });
        };

        return {
            'model' : viewModelAcc,
            'template' : template,
            'init' : init
        };
    }
);
